﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using $myprojectname$.Domain.Abstract;
using $myprojectname$.Domain.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Collections;

    /// <summary>
    ///This is a test class for ProductController and is intended
    ///to contain all ProductController Unit Tests.
    ///</summary>
    [TestClass()]
    public class ProductControllerTest
    {
        /// <summary>
        ///A test for List action.
        ///</summary>
        [TestMethod()]
        public void ListTest()
        {
            // Mock implementation of the IProductRepository Interface
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.GetProducts()).Returns(new List<Product> {
            new Product { Name = "Football", Price = 25 },
            new Product { Name = "Surf board", Price = 179 },
            new Product { Name = "Running shoes", Price = 95 }
            });

            var controller = new ProductController(mock.Object);
            var result = controller.List() as ViewResult;

            var model = result.Model as IEnumerable<Product>;
            Assert.AreEqual(3, model.Count());
        }
    }
